<template>
  <div class="container">
    <div class="app-container">
      <div class="left">
        <div style="margin-bottom:10px">
          <!-- TODO: 单独封装搜索组件 -->
<<<<<<< HEAD
          <inputSear />
=======
       <inputSear @searchValue="handleSearchValue"></inputSear>
>>>>>>> 636ceac30b45ba46120208627b20eade2254cd2c
        </div>
        <!-- TODO: 单独封装树形组件 -->
        <leftTree />
      </div>
      <div class="right">
        <el-row class="opeate-tools" type="flex" justify="end">
          <el-button size="mini" type="primary">添加员工</el-button>
          <el-button size="mini">excel导入</el-button>
          <el-button size="mini">excel导出</el-button>
        </el-row>
        <!-- TODO: 表格组件（不用封装, 如果封装，难度偏大，但是可以挑战，实现就好） -->
        <el-table :data="employeeList">
          <el-table-column prop="staffPhoto" label="头像" align="center" width="80">
            <template #default="{row}">
              <el-avatar v-if="row.staffPhoto" :src="row.staffPhoto" :size="30" />
              <span v-else class="username">{{ row.username.charAt(0) }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="username" label="姓名" />
          <el-table-column prop="mobile" label="手机号" sortable />
          <el-table-column prop="workNumber" label="工号" sortable />
          <el-table-column prop="formOfEmployment" label="聘用形式">
            <template #default="{row}">
              <span v-if="row.formOfEmployment === 1">正式</span>
              <span v-else-if="row.formOfEmployment === 2">非正式</span>
              <span v-else>无</span>
            </template>
          </el-table-column>
          <el-table-column prop="departmentName" label="部门" />
          <el-table-column prop="timeOfEntry" label="入职时间" sortable />
          <el-table-column label="操作" width="280">
            <template>
              <el-button type="text" size="mini">查看</el-button>
              <el-button type="text" size="mini">角色</el-button>
              <el-button slot="reference" type="text" size="mini">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
        <!-- TODO: 单独封装分页组件 -->
        <importPage :query-params.sync="queryParams" :total="total" @getEmployeeList="getEmployeeList" />
      </div>
    </div>
  </div>
</template>

<script>

import { getEmployeeListAPI } from '@/api/employee'
import inputSear from './components/inputSear.vue'
import importPage from './components/import-page.vue'
import leftTree from './components/leftTree.vue'
export default {
  name: 'Employee',
  components: {
    inputSear,
    importPage,
    leftTree
  },
  data() {
    return {
      queryParams: {
        departmentId: null,
        page: 1, // 当前页码
        pagesize: 10,
        keyword: ''
      },
      total: 0, // 记录员工的总数

      // 员工列表数据
      employeeList: []
    }
  },
  created() {
    // 获取员工列表
    this.getEmployeeList()
  },
  methods: {
    // 获取员工列表
    async getEmployeeList() {
      const { rows, total } = await getEmployeeListAPI(this.queryParams)
      this.employeeList = rows
      this.total = total
      console.log(this.employeeList)
<<<<<<< HEAD
    }

=======
    },
    handleSearchValue(val){
       this.queryParams.page = 1
this.queryParams.keyword = val
 this.getEmployeeList()
    }
    
>>>>>>> 636ceac30b45ba46120208627b20eade2254cd2c
  // // 点击分页器的页码
  //   handleCurrentChange(currentPage) {
  //     console.log(currentPage);
  //     // 更新当前页码
  //     this.queryParmas.page = currentPage
  //     // 加载对应页码的员工列表
  //     this.getEmployeeList()
  //   },
  }

}
</script>

<style lang="scss" scoped>
.app-container {
  background: #fff;
  display: flex;
  .left {
    width: 280px;
    padding: 20px;
    border-right: 1px solid #eaeef4;
  }
  .right {
    flex: 1;
    padding: 20px;
    .opeate-tools {
      margin:10px ;
    }
    .username {
      height: 30px;
      width: 30px;
      line-height: 30px;
      text-align: center;
      border-radius: 50%;
      color: #fff;
      background: #04C9BE;
      font-size: 12px;
      display:inline-block;
    }
  }
}

</style>
